ReactOS 0.4.17-dev-116-ga4b6fe9
rtlbitmap.c
Go to the documentation of this file.
1/* Unit test suite for Rtl bitmap functions
2 *
3 * Copyright 2002 Jon Griffiths
4 *
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.
9 *
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.
14 *
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
18 *
19 * NOTES
20 * We use function pointers here as some of the bitmap functions exist only
21 * in later versions of ntdll.
22 */
23
24#include <stdarg.h>
25
26#include "ntstatus.h"
27#define WIN32_NO_STATUS
28#include "windef.h"
29#include "winbase.h"
30#include "winternl.h"
31#include "wine/test.h"
32
33#ifdef __WINE_WINTERNL_H
34
35/* Function ptrs for ordinal calls */
36static HMODULE hntdll = 0;
37static VOID (WINAPI *pRtlInitializeBitMap)(PRTL_BITMAP,LPBYTE,ULONG);
38static VOID (WINAPI *pRtlSetAllBits)(PRTL_BITMAP);
39static VOID (WINAPI *pRtlClearAllBits)(PRTL_BITMAP);
40static VOID (WINAPI *pRtlSetBits)(PRTL_BITMAP,ULONG,ULONG);
41static VOID (WINAPI *pRtlClearBits)(PRTL_BITMAP,ULONG,ULONG);
42static BOOLEAN (WINAPI *pRtlAreBitsSet)(PRTL_BITMAP,ULONG,ULONG);
43static BOOLEAN (WINAPI *pRtlAreBitsClear)(PRTL_BITMAP,ULONG,ULONG);
44static ULONG (WINAPI *pRtlFindSetBitsAndClear)(PRTL_BITMAP,ULONG,ULONG);
45static ULONG (WINAPI *pRtlFindClearBitsAndSet)(PRTL_BITMAP,ULONG,ULONG);
46static CCHAR (WINAPI *pRtlFindMostSignificantBit)(ULONGLONG);
47static CCHAR (WINAPI *pRtlFindLeastSignificantBit)(ULONGLONG);
48static ULONG (WINAPI *pRtlFindSetRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
49static ULONG (WINAPI *pRtlFindClearRuns)(PRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN);
50static ULONG (WINAPI *pRtlFindNextForwardRunSet)(PRTL_BITMAP,ULONG,PULONG);
51static ULONG (WINAPI *pRtlFindNextForwardRunClear)(PRTL_BITMAP,ULONG,PULONG);
52static ULONG (WINAPI *pRtlNumberOfSetBits)(PRTL_BITMAP);
53static ULONG (WINAPI *pRtlNumberOfClearBits)(PRTL_BITMAP);
54static ULONG (WINAPI *pRtlFindLongestRunSet)(PRTL_BITMAP,PULONG);
55static ULONG (WINAPI *pRtlFindLongestRunClear)(PRTL_BITMAP,PULONG);
56
57static BYTE buff[256];
58static RTL_BITMAP bm;
59
60static void InitFunctionPtrs(void)
61{
62 hntdll = LoadLibraryA("ntdll.dll");
63 ok(hntdll != 0, "LoadLibrary failed\n");
64 if (hntdll)
65 {
66 pRtlInitializeBitMap = (void *)GetProcAddress(hntdll, "RtlInitializeBitMap");
67 pRtlSetAllBits = (void *)GetProcAddress(hntdll, "RtlSetAllBits");
68 pRtlClearAllBits = (void *)GetProcAddress(hntdll, "RtlClearAllBits");
69 pRtlSetBits = (void *)GetProcAddress(hntdll, "RtlSetBits");
70 pRtlClearBits = (void *)GetProcAddress(hntdll, "RtlClearBits");
71 pRtlAreBitsSet = (void *)GetProcAddress(hntdll, "RtlAreBitsSet");
72 pRtlAreBitsClear = (void *)GetProcAddress(hntdll, "RtlAreBitsClear");
73 pRtlNumberOfSetBits = (void *)GetProcAddress(hntdll, "RtlNumberOfSetBits");
74 pRtlNumberOfClearBits = (void *)GetProcAddress(hntdll, "RtlNumberOfClearBits");
75 pRtlFindSetBitsAndClear = (void *)GetProcAddress(hntdll, "RtlFindSetBitsAndClear");
76 pRtlFindClearBitsAndSet = (void *)GetProcAddress(hntdll, "RtlFindClearBitsAndSet");
77 pRtlFindMostSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindMostSignificantBit");
78 pRtlFindLeastSignificantBit = (void *)GetProcAddress(hntdll, "RtlFindLeastSignificantBit");
79 pRtlFindSetRuns = (void *)GetProcAddress(hntdll, "RtlFindSetRuns");
80 pRtlFindClearRuns = (void *)GetProcAddress(hntdll, "RtlFindClearRuns");
81 pRtlFindNextForwardRunSet = (void *)GetProcAddress(hntdll, "RtlFindNextForwardRunSet");
82 pRtlFindNextForwardRunClear = (void *)GetProcAddress(hntdll, "RtlFindNextForwardRunClear");
83 pRtlFindLongestRunSet = (void *)GetProcAddress(hntdll, "RtlFindLongestRunSet");
84 pRtlFindLongestRunClear = (void *)GetProcAddress(hntdll, "RtlFindLongestRunClear");
85 }
86}
87
88static void test_RtlInitializeBitMap(void)
89{
90 bm.SizeOfBitMap = 0;
91 bm.Buffer = 0;
92
93 memset(buff, 0, sizeof(buff));
94 buff[0] = 77; /* Check buffer is not written to during init */
95 buff[79] = 77;
96
97 pRtlInitializeBitMap(&bm, buff, 800);
98 ok(bm.SizeOfBitMap == 800, "size uninitialised\n");
99 ok(bm.Buffer == (PULONG)buff,"buffer uninitialised\n");
100 ok(buff[0] == 77 && buff[79] == 77, "wrote to buffer\n");
101}
102
103static void test_RtlSetAllBits(void)
104{
105 if (!pRtlSetAllBits)
106 return;
107
108 memset(buff, 0 , sizeof(buff));
109 pRtlInitializeBitMap(&bm, buff, 1);
110
111 pRtlSetAllBits(&bm);
112 ok(buff[0] == 0xff && buff[1] == 0xff && buff[2] == 0xff &&
113 buff[3] == 0xff, "didn't round up size\n");
114 ok(buff[4] == 0, "set more than rounded size\n");
115}
116
117static void test_RtlClearAllBits(void)
118{
119 if (!pRtlClearAllBits)
120 return;
121
122 memset(buff, 0xff , sizeof(buff));
123 pRtlInitializeBitMap(&bm, buff, 1);
124
125 pRtlClearAllBits(&bm);
126 ok(!buff[0] && !buff[1] && !buff[2] && !buff[3], "didn't round up size\n");
127 ok(buff[4] == 0xff, "cleared more than rounded size\n");
128}
129
130static void test_RtlSetBits(void)
131{
132 if (!pRtlSetBits)
133 return;
134
135 memset(buff, 0 , sizeof(buff));
136 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
137
138 pRtlSetBits(&bm, 0, 1);
139 ok(buff[0] == 1, "didn't set 1st bit\n");
140
141 buff[0] = 0;
142 pRtlSetBits(&bm, 7, 2);
143 ok(buff[0] == 0x80 && buff[1] == 1, "didn't span w/len < 8\n");
144
145 buff[0] = buff[1] = 0;
146 pRtlSetBits(&bm, 7, 10);
147 ok(buff[0] == 0x80 && buff[1] == 0xff && buff[2] == 1, "didn't span w/len > 8\n");
148
149 buff[0] = buff[1] = buff[2] = 0;
150 pRtlSetBits(&bm, 0, 8); /* 1st byte */
151 ok(buff[0] == 0xff, "didn't set all bits\n");
152 ok(!buff[1], "set too many bits\n");
153
154 pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* last bit */
155 ok(buff[sizeof(buff)-1] == 0x80, "didn't set last bit\n");
156}
157
158static void test_RtlClearBits(void)
159{
160 if (!pRtlClearBits)
161 return;
162
163 memset(buff, 0xff , sizeof(buff));
164 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
165
166 pRtlClearBits(&bm, 0, 1);
167 ok(buff[0] == 0xfe, "didn't clear 1st bit\n");
168
169 buff[0] = 0xff;
170 pRtlClearBits(&bm, 7, 2);
171 ok(buff[0] == 0x7f && buff[1] == 0xfe, "didn't span w/len < 8\n");
172
173 buff[0] = buff[1] = 0xff;
174 pRtlClearBits(&bm, 7, 10);
175 ok(buff[0] == 0x7f && buff[1] == 0 && buff[2] == 0xfe, "didn't span w/len > 8\n");
176
177 buff[0] = buff[1] = buff[2] = 0xff;
178 pRtlClearBits(&bm, 0, 8); /* 1st byte */
179 ok(!buff[0], "didn't clear all bits\n");
180 ok(buff[1] == 0xff, "cleared too many bits\n");
181
182 pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
183 ok(buff[sizeof(buff)-1] == 0x7f, "didn't set last bit\n");
184}
185
186static void test_RtlCheckBit(void)
187{
188 BOOLEAN bRet;
189
190 memset(buff, 0 , sizeof(buff));
191 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
192 pRtlSetBits(&bm, 0, 1);
193 pRtlSetBits(&bm, 7, 2);
194 pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
195
196 bRet = RtlCheckBit(&bm, 0);
197 ok (bRet, "didn't find set bit\n");
198 bRet = RtlCheckBit(&bm, 7);
199 ok (bRet, "didn't find set bit\n");
200 bRet = RtlCheckBit(&bm, 8);
201 ok (bRet, "didn't find set bit\n");
202 bRet = RtlCheckBit(&bm, sizeof(buff)*8-1);
203 ok (bRet, "didn't find set bit\n");
204 bRet = RtlCheckBit(&bm, 1);
205 ok (!bRet, "found non set bit\n");
206 bRet = RtlCheckBit(&bm, sizeof(buff)*8-2);
207 ok (!bRet, "found non set bit\n");
208}
209
210static void test_RtlAreBitsSet(void)
211{
212 BOOLEAN bRet;
213
214 if (!pRtlAreBitsSet)
215 return;
216
217 memset(buff, 0 , sizeof(buff));
218 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
219
220 bRet = pRtlAreBitsSet(&bm, 0, 1);
221 ok (!bRet, "found set bits after init\n");
222
223 pRtlSetBits(&bm, 0, 1);
224 bRet = pRtlAreBitsSet(&bm, 0, 1);
225 ok (bRet, "didn't find set bits\n");
226
227 buff[0] = 0;
228 pRtlSetBits(&bm, 7, 2);
229 bRet = pRtlAreBitsSet(&bm, 7, 2);
230 ok(bRet, "didn't find w/len < 8\n");
231 bRet = pRtlAreBitsSet(&bm, 6, 3);
232 ok(!bRet, "found non set bit\n");
233 bRet = pRtlAreBitsSet(&bm, 7, 3);
234 ok(!bRet, "found non set bit\n");
235
236 buff[0] = buff[1] = 0;
237 pRtlSetBits(&bm, 7, 10);
238 bRet = pRtlAreBitsSet(&bm, 7, 10);
239 ok(bRet, "didn't find w/len < 8\n");
240 bRet = pRtlAreBitsSet(&bm, 6, 11);
241 ok(!bRet, "found non set bit\n");
242 bRet = pRtlAreBitsSet(&bm, 7, 11);
243 ok(!bRet, "found non set bit\n");
244
245 buff[0] = buff[1] = buff[2] = 0;
246 pRtlSetBits(&bm, 0, 8); /* 1st byte */
247 bRet = pRtlAreBitsSet(&bm, 0, 8);
248 ok(bRet, "didn't find whole byte\n");
249
250 pRtlSetBits(&bm, sizeof(buff)*8-1, 1);
251 bRet = pRtlAreBitsSet(&bm, sizeof(buff)*8-1, 1);
252 ok(bRet, "didn't find last bit\n");
253}
254
255static void test_RtlAreBitsClear(void)
256{
257 BOOLEAN bRet;
258
259 if (!pRtlAreBitsClear)
260 return;
261
262 memset(buff, 0xff , sizeof(buff));
263 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
264
265 bRet = pRtlAreBitsClear(&bm, 0, 1);
266 ok (!bRet, "found clear bits after init\n");
267
268 pRtlClearBits(&bm, 0, 1);
269 bRet = pRtlAreBitsClear(&bm, 0, 1);
270 ok (bRet, "didn't find set bits\n");
271
272 buff[0] = 0xff;
273 pRtlClearBits(&bm, 7, 2);
274 bRet = pRtlAreBitsClear(&bm, 7, 2);
275 ok(bRet, "didn't find w/len < 8\n");
276 bRet = pRtlAreBitsClear(&bm, 6, 3);
277 ok(!bRet, "found non clear bit\n");
278 bRet = pRtlAreBitsClear(&bm, 7, 3);
279 ok(!bRet, "found non clear bit\n");
280
281 buff[0] = buff[1] = 0xff;
282 pRtlClearBits(&bm, 7, 10);
283 bRet = pRtlAreBitsClear(&bm, 7, 10);
284 ok(bRet, "didn't find w/len < 8\n");
285 bRet = pRtlAreBitsClear(&bm, 6, 11);
286 ok(!bRet, "found non clear bit\n");
287 bRet = pRtlAreBitsClear(&bm, 7, 11);
288 ok(!bRet, "found non clear bit\n");
289
290 buff[0] = buff[1] = buff[2] = 0xff;
291 pRtlClearBits(&bm, 0, 8); /* 1st byte */
292 bRet = pRtlAreBitsClear(&bm, 0, 8);
293 ok(bRet, "didn't find whole byte\n");
294
295 pRtlClearBits(&bm, sizeof(buff)*8-1, 1);
296 bRet = pRtlAreBitsClear(&bm, sizeof(buff)*8-1, 1);
297 ok(bRet, "didn't find last bit\n");
298}
299
300static void test_RtlNumberOfSetBits(void)
301{
302 ULONG ulCount;
303
304 if (!pRtlNumberOfSetBits)
305 return;
306
307 memset(buff, 0 , sizeof(buff));
308 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
309
310 ulCount = pRtlNumberOfSetBits(&bm);
311 ok(ulCount == 0, "set bits after init\n");
312
313 pRtlSetBits(&bm, 0, 1); /* Set 1st bit */
314 ulCount = pRtlNumberOfSetBits(&bm);
315 ok(ulCount == 1, "count wrong\n");
316
317 pRtlSetBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
318 ulCount = pRtlNumberOfSetBits(&bm);
319 ok(ulCount == 8+1, "count wrong\n");
320
321 pRtlSetBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
322 ulCount = pRtlNumberOfSetBits(&bm);
323 ok(ulCount == 8+1+33, "count wrong\n");
324
325 pRtlSetBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
326 ulCount = pRtlNumberOfSetBits(&bm);
327 ok(ulCount == 8+1+33+1, "count wrong\n");
328}
329
330static void test_RtlNumberOfClearBits(void)
331{
332 ULONG ulCount;
333
334 if (!pRtlNumberOfClearBits)
335 return;
336
337 memset(buff, 0xff , sizeof(buff));
338 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
339
340 ulCount = pRtlNumberOfClearBits(&bm);
341 ok(ulCount == 0, "cleared bits after init\n");
342
343 pRtlClearBits(&bm, 0, 1); /* Set 1st bit */
344 ulCount = pRtlNumberOfClearBits(&bm);
345 ok(ulCount == 1, "count wrong\n");
346
347 pRtlClearBits(&bm, 7, 8); /* 8 more, spanning bytes 1-2 */
348 ulCount = pRtlNumberOfClearBits(&bm);
349 ok(ulCount == 8+1, "count wrong\n");
350
351 pRtlClearBits(&bm, 17, 33); /* 33 more crossing ULONG boundary */
352 ulCount = pRtlNumberOfClearBits(&bm);
353 ok(ulCount == 8+1+33, "count wrong\n");
354
355 pRtlClearBits(&bm, sizeof(buff)*8-1, 1); /* Set last bit */
356 ulCount = pRtlNumberOfClearBits(&bm);
357 ok(ulCount == 8+1+33+1, "count wrong\n");
358}
359
360/* Note: this tests RtlFindSetBits also */
361static void test_RtlFindSetBitsAndClear(void)
362{
363 BOOLEAN bRet;
364 ULONG ulPos;
365
366 if (!pRtlFindSetBitsAndClear)
367 return;
368
369 memset(buff, 0, sizeof(buff));
370 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
371
372 pRtlSetBits(&bm, 0, 32);
373 ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
374 ok (ulPos == 0, "didn't find bits\n");
375 if(ulPos == 0)
376 {
377 bRet = pRtlAreBitsClear(&bm, 0, 32);
378 ok (bRet, "found but didn't clear\n");
379 }
380
381 memset(buff, 0 , sizeof(buff));
382 pRtlSetBits(&bm, 40, 77);
383 ulPos = pRtlFindSetBitsAndClear(&bm, 77, 0);
384 ok (ulPos == 40, "didn't find bits\n");
385 if(ulPos == 40)
386 {
387 bRet = pRtlAreBitsClear(&bm, 40, 77);
388 ok (bRet, "found but didn't clear\n");
389 }
390}
391
392/* Note: this tests RtlFindClearBits also */
393static void test_RtlFindClearBitsAndSet(void)
394{
395 BOOLEAN bRet;
396 ULONG ulPos;
397
398 if (!pRtlFindClearBitsAndSet)
399 return;
400
401 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
402
403 memset(buff, 0xff, sizeof(buff));
404 pRtlSetBits(&bm, 0, 32);
405 ulPos = pRtlFindSetBitsAndClear(&bm, 32, 0);
406 ok (ulPos == 0, "didn't find bits\n");
407 if(ulPos == 0)
408 {
409 bRet = pRtlAreBitsClear(&bm, 0, 32);
410 ok (bRet, "found but didn't clear\n");
411 }
412
413 memset(buff, 0xff , sizeof(buff));
414 pRtlClearBits(&bm, 40, 77);
415 ulPos = pRtlFindClearBitsAndSet(&bm, 77, 50);
416 ok (ulPos == 40, "didn't find bits\n");
417 if(ulPos == 40)
418 {
419 bRet = pRtlAreBitsSet(&bm, 40, 77);
420 ok (bRet, "found but didn't set\n");
421 }
422}
423
424static void test_RtlFindMostSignificantBit(void)
425{
426 int i;
427 signed char cPos;
428 ULONGLONG ulLong;
429
430 if (!pRtlFindMostSignificantBit)
431 return;
432
433 for (i = 0; i < 64; i++)
434 {
435 ulLong = 1ul;
436 ulLong <<= i;
437
438 cPos = pRtlFindMostSignificantBit(ulLong);
439 ok (cPos == i, "didn't find MSB 0x%s %d %d\n",
440 wine_dbgstr_longlong(ulLong ), i, cPos);
441
442 /* Set all bits lower than bit i */
443 ulLong = ((ulLong - 1) << 1) | 1;
444
445 cPos = pRtlFindMostSignificantBit(ulLong);
446 ok (cPos == i, "didn't find MSB 0x%s %d %d\n",
447 wine_dbgstr_longlong(ulLong ), i, cPos);
448 }
449 cPos = pRtlFindMostSignificantBit(0);
450 ok (cPos == -1, "found bit when not set\n");
451}
452
453static void test_RtlFindLeastSignificantBit(void)
454{
455 int i;
456 signed char cPos;
457 ULONGLONG ulLong;
458
459 if (!pRtlFindLeastSignificantBit)
460 return;
461
462 for (i = 0; i < 64; i++)
463 {
464 ulLong = (ULONGLONG)1 << i;
465
466 cPos = pRtlFindLeastSignificantBit(ulLong);
467 ok (cPos == i, "didn't find LSB 0x%s %d %d\n",
468 wine_dbgstr_longlong(ulLong ), i, cPos);
469
470 ulLong = ~((ULONGLONG)0) << i;
471
472 cPos = pRtlFindLeastSignificantBit(ulLong);
473 ok (cPos == i, "didn't find LSB 0x%s %d %d\n",
474 wine_dbgstr_longlong(ulLong ), i, cPos);
475 }
476 cPos = pRtlFindLeastSignificantBit(0);
477 ok (cPos == -1, "found bit when not set\n");
478}
479
480/* Note: Also tests RtlFindLongestRunSet() */
481static void test_RtlFindSetRuns(void)
482{
483 RTL_BITMAP_RUN runs[16];
484 ULONG ulCount;
485
486 if (!pRtlFindSetRuns)
487 return;
488
489 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
490
491 memset(buff, 0, sizeof(buff));
492 ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
493 ok (ulCount == 0, "found set bits in empty bitmap\n");
494
495 memset(runs, 0, sizeof(runs));
496 memset(buff, 0xff, sizeof(buff));
497 ulCount = pRtlFindSetRuns(&bm, runs, 16, TRUE);
498 ok (ulCount == 1, "didn't find set bits\n");
499 ok (runs[0].StartingIndex == 0,"bad start\n");
500 ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
501
502 /* Set up 3 runs */
503 memset(runs, 0, sizeof(runs));
504 memset(buff, 0, sizeof(buff));
505 pRtlSetBits(&bm, 7, 19);
506 pRtlSetBits(&bm, 101, 3);
507 pRtlSetBits(&bm, 1877, 33);
508
509 /* Get first 2 */
510 ulCount = pRtlFindSetRuns(&bm, runs, 2, FALSE);
511 ok(ulCount == 2, "RtlFindClearRuns returned %ld, expected 2\n", ulCount);
512 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
513 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
514 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
515 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
516 ok (runs[2].StartingIndex == 0,"found extra run\n");
517
518 /* Get longest 3 */
519 memset(runs, 0, sizeof(runs));
520 ulCount = pRtlFindSetRuns(&bm, runs, 2, TRUE);
521 ok(ulCount == 2, "RtlFindClearRuns returned %ld, expected 2\n", ulCount);
522 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
523 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
524 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
525 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
526 ok (runs[2].StartingIndex == 0,"found extra run\n");
527
528 /* Get all 3 */
529 memset(runs, 0, sizeof(runs));
530 ulCount = pRtlFindSetRuns(&bm, runs, 3, TRUE);
531 ok(ulCount == 3, "RtlFindClearRuns returned %ld, expected 3\n", ulCount);
532 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
533 runs[0].StartingIndex == 1877,"bad find\n");
534 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
535 runs[1].StartingIndex == 1877,"bad find\n");
536 ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
537 runs[2].StartingIndex == 1877,"bad find\n");
538 ok (runs[0].NumberOfBits + runs[1].NumberOfBits
539 + runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
540 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
541 ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
542 ok (runs[3].StartingIndex == 0,"found extra run\n");
543
544 if (pRtlFindLongestRunSet)
545 {
546 ULONG ulStart = 0;
547
548 ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
549 ok(ulCount == 33 && ulStart == 1877,"didn't find longest %ld %ld\n",ulCount,ulStart);
550
551 memset(buff, 0, sizeof(buff));
552 ulCount = pRtlFindLongestRunSet(&bm, &ulStart);
553 ok(ulCount == 0,"found longest when none set\n");
554 }
555}
556
557/* Note: Also tests RtlFindLongestRunClear() */
558static void test_RtlFindClearRuns(void)
559{
560 RTL_BITMAP_RUN runs[16];
561 ULONG ulCount;
562
563 if (!pRtlFindClearRuns)
564 return;
565
566 pRtlInitializeBitMap(&bm, buff, sizeof(buff)*8);
567
568 memset(buff, 0xff, sizeof(buff));
569 ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
570 ok (ulCount == 0, "found clear bits in full bitmap\n");
571
572 memset(runs, 0, sizeof(runs));
573 memset(buff, 0, sizeof(buff));
574 ulCount = pRtlFindClearRuns(&bm, runs, 16, TRUE);
575 ok (ulCount == 1, "didn't find clear bits\n");
576 ok (runs[0].StartingIndex == 0,"bad start\n");
577 ok (runs[0].NumberOfBits == sizeof(buff)*8,"bad size\n");
578
579 /* Set up 3 runs */
580 memset(runs, 0, sizeof(runs));
581 memset(buff, 0xff, sizeof(buff));
582 pRtlClearBits(&bm, 7, 19);
583 pRtlClearBits(&bm, 101, 3);
584 pRtlClearBits(&bm, 1877, 33);
585
586 /* Get first 2 */
587 ulCount = pRtlFindClearRuns(&bm, runs, 2, FALSE);
588 ok(ulCount == 2, "RtlFindClearRuns returned %ld, expected 2\n", ulCount);
589 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101,"bad find\n");
590 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101,"bad find\n");
591 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 19 + 3,"bad size\n");
592 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
593 ok (runs[2].StartingIndex == 0,"found extra run\n");
594
595 /* Get longest 3 */
596 memset(runs, 0, sizeof(runs));
597 ulCount = pRtlFindClearRuns(&bm, runs, 2, TRUE);
598 ok(ulCount == 2, "RtlFindClearRuns returned %ld, expected 2\n", ulCount);
599 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 1877,"bad find\n");
600 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 1877,"bad find\n");
601 ok (runs[0].NumberOfBits + runs[1].NumberOfBits == 33 + 19,"bad size\n");
602 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
603 ok (runs[2].StartingIndex == 0,"found extra run\n");
604
605 /* Get all 3 */
606 memset(runs, 0, sizeof(runs));
607 ulCount = pRtlFindClearRuns(&bm, runs, 3, TRUE);
608 ok(ulCount == 3, "RtlFindClearRuns returned %ld, expected 3\n", ulCount);
609 ok (runs[0].StartingIndex == 7 || runs[0].StartingIndex == 101 ||
610 runs[0].StartingIndex == 1877,"bad find\n");
611 ok (runs[1].StartingIndex == 7 || runs[1].StartingIndex == 101 ||
612 runs[1].StartingIndex == 1877,"bad find\n");
613 ok (runs[2].StartingIndex == 7 || runs[2].StartingIndex == 101 ||
614 runs[2].StartingIndex == 1877,"bad find\n");
615 ok (runs[0].NumberOfBits + runs[1].NumberOfBits
616 + runs[2].NumberOfBits == 19 + 3 + 33,"bad size\n");
617 ok (runs[0].StartingIndex != runs[1].StartingIndex,"found run twice\n");
618 ok (runs[1].StartingIndex != runs[2].StartingIndex,"found run twice\n");
619 ok (runs[3].StartingIndex == 0,"found extra run\n");
620
621 if (pRtlFindLongestRunClear)
622 {
623 ULONG ulStart = 0;
624
625 ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
626 ok(ulCount == 33 && ulStart == 1877,"didn't find longest\n");
627
628 memset(buff, 0xff, sizeof(buff));
629 ulCount = pRtlFindLongestRunClear(&bm, &ulStart);
630 ok(ulCount == 0,"found longest when none clear\n");
631 }
632
633}
634
635static void test_RtlFindNextForwardRunSet(void)
636{
637 BYTE mask[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff };
638 ULONG ulStart = 0;
639 ULONG ulCount, lpPos;
640 if (!pRtlFindNextForwardRunSet)
641 return;
642
643 pRtlInitializeBitMap(&bm, mask, 62);
644 ulCount = pRtlFindNextForwardRunSet(&bm, ulStart, &lpPos);
645 ok(ulCount == 6, "Invalid length of found set run: %ld, expected 6\n", ulCount);
646 ok(lpPos == 56, "Invalid position of found set run: %ld, expected 56\n", lpPos);
647}
648
649static void test_RtlFindNextForwardRunClear(void)
650{
651 BYTE mask[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
652 ULONG ulStart = 0;
653 ULONG ulCount, lpPos;
654 if (!pRtlFindNextForwardRunClear)
655 return;
656
657 pRtlInitializeBitMap(&bm, mask, 62);
658 ulCount = pRtlFindNextForwardRunClear(&bm, ulStart, &lpPos);
659 ok(ulCount == 6, "Invalid length of found clear run: %ld, expected 6\n", ulCount);
660 ok(lpPos == 56, "Invalid position of found clear run: %ld, expected 56\n", lpPos);
661}
662
663#endif
664
665START_TEST(rtlbitmap)
666{
667#ifdef __WINE_WINTERNL_H
669
670 if (pRtlInitializeBitMap)
671 {
672 test_RtlInitializeBitMap();
673 test_RtlSetAllBits();
674 test_RtlClearAllBits();
675 test_RtlSetBits();
676 test_RtlClearBits();
677 test_RtlCheckBit();
678 test_RtlAreBitsSet();
679 test_RtlAreBitsClear();
680 test_RtlNumberOfSetBits();
681 test_RtlNumberOfClearBits();
682 test_RtlFindSetBitsAndClear();
683 test_RtlFindClearBitsAndSet();
684 test_RtlFindMostSignificantBit();
685 test_RtlFindLeastSignificantBit();
686 test_RtlFindSetRuns();
687 test_RtlFindClearRuns();
688 test_RtlFindNextForwardRunSet();
689 test_RtlFindNextForwardRunClear();
690 }
691#endif
692}
#define VOID
Definition: acefi.h:82
unsigned char BOOLEAN
Definition: actypes.h:127
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define RtlCheckBit
Definition: dbgbitmap.h:349
#define PRTL_BITMAP
Definition: dbgbitmap.h:324
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static unsigned char buff[32768]
Definition: fatten.c:17
GLenum GLint GLuint mask
Definition: glext.h:6028
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void InitFunctionPtrs(void)
Definition: registry.c:102
static HINSTANCE hntdll
Definition: process.c:68
#define BOOLEAN
Definition: pedump.c:73
#define memset(x, y, z)
Definition: compat.h:39
ULONG SizeOfBitMap
Definition: typedefs.h:90
PULONG Buffer
Definition: typedefs.h:91
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * LPBYTE
Definition: typedefs.h:53
uint64_t ULONGLONG
Definition: typedefs.h:67
struct _RTL_BITMAP_RUN * PRTL_BITMAP_RUN
uint32_t ULONG
Definition: typedefs.h:59
char CCHAR
Definition: typedefs.h:51
#define WINAPI
Definition: msvc.h:6
_In_ ULONG StartingIndex
Definition: rtlfuncs.h:398
unsigned char BYTE
Definition: xxhash.c:193