1 /*
2    Copyright (c) 2006, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #include "my_config.h"
26 #include <gtest/gtest.h>
27 
28 #include <my_global.h>
29 #include <my_thread.h>
30 #include <my_bitmap.h>
31 
32 namespace my_bitmap_unittest {
33 
34 const uint MAX_TESTED_BITMAP_SIZE= 1024;
35 
get_rand_bit(uint bitsize)36 uint get_rand_bit(uint bitsize)
37 {
38   return (rand() % bitsize);
39 }
40 
test_set_get_clear_bit(MY_BITMAP * map,uint bitsize)41 bool test_set_get_clear_bit(MY_BITMAP *map, uint bitsize)
42 {
43   uint i, test_bit;
44   uint no_loops= bitsize > 128 ? 128 : bitsize;
45   for (i=0; i < no_loops; i++)
46   {
47     test_bit= get_rand_bit(bitsize);
48     bitmap_set_bit(map, test_bit);
49     if (!bitmap_is_set(map, test_bit))
50       goto error1;
51     bitmap_clear_bit(map, test_bit);
52     if (bitmap_is_set(map, test_bit))
53       goto error2;
54   }
55   return false;
56 error1:
57   ADD_FAILURE() << "Error in set bit  bit=" << test_bit;
58   return true;
59 error2:
60   ADD_FAILURE() << "Error in clear bit  bit=" << test_bit;
61   return true;
62 }
63 
test_flip_bit(MY_BITMAP * map,uint bitsize)64 bool test_flip_bit(MY_BITMAP *map, uint bitsize)
65 {
66   uint i, test_bit;
67   uint no_loops= bitsize > 128 ? 128 : bitsize;
68   for (i=0; i < no_loops; i++)
69   {
70     test_bit= get_rand_bit(bitsize);
71     bitmap_flip_bit(map, test_bit);
72     if (!bitmap_is_set(map, test_bit))
73       goto error1;
74     bitmap_flip_bit(map, test_bit);
75     if (bitmap_is_set(map, test_bit))
76       goto error2;
77   }
78   return false;
79 error1:
80   ADD_FAILURE() << "Error in flip bit 1  bit=" << test_bit;
81   return true;
82 error2:
83   ADD_FAILURE() << "Error in flip bit 2  bit=" << test_bit;
84   return true;
85 }
86 
test_get_all_bits(MY_BITMAP * map,uint bitsize)87 bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
88 {
89   uint i;
90   bitmap_set_all(map);
91   if (!bitmap_is_set_all(map))
92     goto error1;
93   if (!bitmap_is_prefix(map, bitsize))
94     goto error5;
95   bitmap_clear_all(map);
96   if (!bitmap_is_clear_all(map))
97     goto error2;
98   if (!bitmap_is_prefix(map, 0))
99     goto error6;
100   for (i=0; i<bitsize;i++)
101     bitmap_set_bit(map, i);
102   if (!bitmap_is_set_all(map))
103     goto error3;
104   for (i=0; i<bitsize;i++)
105     bitmap_clear_bit(map, i);
106   if (!bitmap_is_clear_all(map))
107     goto error4;
108   return false;
109 error1:
110   ADD_FAILURE() << "Error in set_all";
111   return true;
112 error2:
113   ADD_FAILURE() << "Error in clear_all";
114   return true;
115 error3:
116   ADD_FAILURE() << "Error in bitmap_is_set_all";
117   return true;
118 error4:
119   ADD_FAILURE() << "Error in bitmap_is_clear_all";
120   return true;
121 error5:
122   ADD_FAILURE() << "Error in set_all through set_prefix";
123   return true;
124 error6:
125   ADD_FAILURE() << "Error in clear_all through set_prefix";
126   return true;
127 }
128 
test_compare_operators(MY_BITMAP * map,uint bitsize)129 bool test_compare_operators(MY_BITMAP *map, uint bitsize)
130 {
131   uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
132   uint no_loops= bitsize > 128 ? 128 : bitsize;
133   MY_BITMAP map2_obj, map3_obj;
134   MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
135   my_bitmap_map map2buf[MAX_TESTED_BITMAP_SIZE];
136   my_bitmap_map map3buf[MAX_TESTED_BITMAP_SIZE];
137   bitmap_init(&map2_obj, map2buf, bitsize, false);
138   bitmap_init(&map3_obj, map3buf, bitsize, false);
139   bitmap_clear_all(map2);
140   bitmap_clear_all(map3);
141   for (i=0; i < no_loops; i++)
142   {
143     test_bit1=get_rand_bit(bitsize);
144     bitmap_set_prefix(map, test_bit1);
145     test_bit2=get_rand_bit(bitsize);
146     bitmap_set_prefix(map2, test_bit2);
147     bitmap_intersect(map, map2);
148     test_bit3= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
149     bitmap_set_prefix(map3, test_bit3);
150     if (!bitmap_cmp(map, map3))
151       goto error1;
152     bitmap_clear_all(map);
153     bitmap_clear_all(map2);
154     bitmap_clear_all(map3);
155     test_bit1=get_rand_bit(bitsize);
156     test_bit2=get_rand_bit(bitsize);
157     test_bit3=get_rand_bit(bitsize);
158     bitmap_set_prefix(map, test_bit1);
159     bitmap_set_prefix(map2, test_bit2);
160     test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
161     bitmap_set_prefix(map3, test_bit3);
162     bitmap_union(map, map2);
163     if (!bitmap_cmp(map, map3))
164       goto error2;
165     bitmap_clear_all(map);
166     bitmap_clear_all(map2);
167     bitmap_clear_all(map3);
168     test_bit1=get_rand_bit(bitsize);
169     test_bit2=get_rand_bit(bitsize);
170     test_bit3=get_rand_bit(bitsize);
171     bitmap_set_prefix(map, test_bit1);
172     bitmap_set_prefix(map2, test_bit2);
173     bitmap_xor(map, map2);
174     test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
175     test_bit4= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
176     bitmap_set_prefix(map3, test_bit3);
177     for (j=0; j < test_bit4; j++)
178       bitmap_clear_bit(map3, j);
179     if (!bitmap_cmp(map, map3))
180       goto error3;
181     bitmap_clear_all(map);
182     bitmap_clear_all(map2);
183     bitmap_clear_all(map3);
184     test_bit1=get_rand_bit(bitsize);
185     test_bit2=get_rand_bit(bitsize);
186     test_bit3=get_rand_bit(bitsize);
187     bitmap_set_prefix(map, test_bit1);
188     bitmap_set_prefix(map2, test_bit2);
189     bitmap_subtract(map, map2);
190     if (test_bit2 < test_bit1)
191     {
192       bitmap_set_prefix(map3, test_bit1);
193       for (j=0; j < test_bit2; j++)
194         bitmap_clear_bit(map3, j);
195     }
196     if (!bitmap_cmp(map, map3))
197       goto error4;
198     bitmap_clear_all(map);
199     bitmap_clear_all(map2);
200     bitmap_clear_all(map3);
201     test_bit1=get_rand_bit(bitsize);
202     bitmap_set_prefix(map, test_bit1);
203     bitmap_invert(map);
204     bitmap_set_all(map3);
205     for (j=0; j < test_bit1; j++)
206       bitmap_clear_bit(map3, j);
207     if (!bitmap_cmp(map, map3))
208       goto error5;
209     bitmap_clear_all(map);
210     bitmap_clear_all(map3);
211   }
212   return false;
213 error1:
214   ADD_FAILURE() << "intersect error  size1=" << test_bit1
215                 << ",size2=" << test_bit2;
216   return true;
217 error2:
218   ADD_FAILURE() << "union error  size1=" << test_bit1
219                 << ",size2=" << test_bit2;
220   return true;
221 error3:
222   ADD_FAILURE() << "xor error  size1=" << test_bit1
223                 << ",size2=" << test_bit2;
224   return true;
225 error4:
226   ADD_FAILURE() << "subtract error  size1=" << test_bit1
227                 << ",size2=" << test_bit2;
228   return true;
229 error5:
230   ADD_FAILURE() << "invert error  size=" << test_bit1;
231   return true;
232 }
233 
test_count_bits_set(MY_BITMAP * map,uint bitsize)234 bool test_count_bits_set(MY_BITMAP *map, uint bitsize)
235 {
236   uint i, bit_count=0, test_bit;
237   uint no_loops= bitsize > 128 ? 128 : bitsize;
238   for (i=0; i < no_loops; i++)
239   {
240     test_bit=get_rand_bit(bitsize);
241     if (!bitmap_is_set(map, test_bit))
242     {
243       bitmap_set_bit(map, test_bit);
244       bit_count++;
245     }
246   }
247   if (bit_count==0 && bitsize > 0)
248     goto error1;
249   if (bitmap_bits_set(map) != bit_count)
250     goto error2;
251   return false;
252 error1:
253   ADD_FAILURE() << "No bits set";
254   return true;
255 error2:
256   ADD_FAILURE() << "Wrong count of bits set";
257   return true;
258 }
259 
test_get_first_bit(MY_BITMAP * map,uint bitsize)260 bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
261 {
262   uint i, test_bit= 0;
263   uint no_loops= bitsize > 128 ? 128 : bitsize;
264 
265   bitmap_set_all(map);
266   for (i=0; i < bitsize; i++)
267     bitmap_clear_bit(map, i);
268   if (bitmap_get_first_set(map) != MY_BIT_NONE)
269     goto error1;
270   bitmap_clear_all(map);
271   for (i=0; i < bitsize; i++)
272     bitmap_set_bit(map, i);
273   if (bitmap_get_first(map) != MY_BIT_NONE)
274     goto error2;
275   bitmap_clear_all(map);
276 
277   for (i=0; i < no_loops; i++)
278   {
279     test_bit=get_rand_bit(bitsize);
280     bitmap_set_bit(map, test_bit);
281     if (bitmap_get_first_set(map) != test_bit)
282       goto error1;
283     bitmap_set_all(map);
284     bitmap_clear_bit(map, test_bit);
285     if (bitmap_get_first(map) != test_bit)
286       goto error2;
287     bitmap_clear_all(map);
288   }
289   return false;
290 error1:
291   ADD_FAILURE() << "get_first_set error  prefix_size=" << test_bit;
292   return true;
293 error2:
294   ADD_FAILURE() << "get_first error  prefix_size=" << test_bit;
295   return true;
296 }
297 
test_set_next_bit(MY_BITMAP * map,uint bitsize)298 bool test_set_next_bit(MY_BITMAP *map, uint bitsize)
299 {
300   uint i, j, test_bit;
301   uint no_loops= bitsize > 128 ? 128 : bitsize;
302   for (i=0; i < no_loops; i++)
303   {
304     test_bit=get_rand_bit(bitsize);
305     for (j=0; j < test_bit; j++)
306       bitmap_set_next(map);
307     if (!bitmap_is_prefix(map, test_bit))
308       goto error1;
309     bitmap_clear_all(map);
310   }
311   return false;
312 error1:
313   ADD_FAILURE() << "set_next error  prefix_size=" << test_bit;
314   return true;
315 }
316 
test_get_next_bit(MY_BITMAP * map,uint bitsize)317 bool test_get_next_bit(MY_BITMAP *map, uint bitsize)
318 {
319   uint i, bit_count=0, test_bit, next_count=0;
320   uint no_loops= bitsize > 128 ? 128 : bitsize;
321   for (i=0; i < no_loops; i++)
322   {
323     test_bit=get_rand_bit(bitsize);
324     if (!bitmap_is_set(map, test_bit))
325     {
326       bitmap_set_bit(map, test_bit);
327       bit_count++;
328     }
329   }
330   if (bit_count==0 && bitsize > 0)
331     goto error1;
332   if (bitmap_bits_set(map) != bit_count)
333     goto error2;
334 
335   for (test_bit= bitmap_get_first_set(map);
336        test_bit != MY_BIT_NONE;
337        test_bit= bitmap_get_next_set(map, test_bit))
338   {
339     if (test_bit >= bitsize)
340       goto error3;
341     if (!bitmap_is_set(map, test_bit))
342       goto error4;
343     next_count++;
344   }
345   if (next_count != bit_count)
346     goto error5;
347   return false;
348 error1:
349   ADD_FAILURE() << "No bits set";
350   return true;
351 error2:
352   ADD_FAILURE() << "Wrong count of bits set";
353   return true;
354 error3:
355   ADD_FAILURE() << "get_next_set out of range";
356   return true;
357 error4:
358   ADD_FAILURE() << "get_next_set bit not set";
359   return true;
360 error5:
361   ADD_FAILURE() << "Wrong count get_next_set";
362   return true;
363 }
364 
test_prefix(MY_BITMAP * map,uint bitsize)365 bool test_prefix(MY_BITMAP *map, uint bitsize)
366 {
367   uint i, j, test_bit;
368   uint no_loops= bitsize > 128 ? 128 : bitsize;
369   for (i=0; i < no_loops; i++)
370   {
371     test_bit=get_rand_bit(bitsize);
372     bitmap_set_prefix(map, test_bit);
373     if (!bitmap_is_prefix(map, test_bit))
374       goto error1;
375     bitmap_clear_all(map);
376     for (j=0; j < test_bit; j++)
377       bitmap_set_bit(map, j);
378     if (!bitmap_is_prefix(map, test_bit))
379       goto error2;
380     bitmap_set_all(map);
381     for (j=bitsize - 1; ~(j-test_bit); j--)
382       bitmap_clear_bit(map, j);
383     if (!bitmap_is_prefix(map, test_bit))
384       goto error3;
385     bitmap_clear_all(map);
386   }
387   for (i=0; i < bitsize; i++)
388   {
389     if (bitmap_is_prefix(map, i + 1))
390       goto error4;
391     bitmap_set_bit(map, i);
392     if (!bitmap_is_prefix(map, i + 1))
393       goto error5;
394     test_bit=get_rand_bit(bitsize);
395     bitmap_set_bit(map, test_bit);
396     if (test_bit <= i && !bitmap_is_prefix(map, i + 1))
397       goto error5;
398     else if (test_bit > i)
399     {
400       if (bitmap_is_prefix(map, i + 1))
401         goto error4;
402       bitmap_clear_bit(map, test_bit);
403     }
404   }
405   return false;
406 error1:
407   ADD_FAILURE() << "prefix1 error  prefix_size=" << test_bit;
408   return true;
409 error2:
410   ADD_FAILURE() << "prefix2 error  prefix_size=" << test_bit;
411   return true;
412 error3:
413   ADD_FAILURE() << "prefix3 error  prefix_size=" << test_bit;
414   return true;
415 error4:
416   ADD_FAILURE() << "prefix4 error  i=" << i;
417   return true;
418 error5:
419   ADD_FAILURE() << "prefix5 error  i=" << i;
420   return true;
421 }
422 
test_compare(MY_BITMAP * map,uint bitsize)423 bool test_compare(MY_BITMAP *map, uint bitsize)
424 {
425   MY_BITMAP map2;
426   my_bitmap_map map2buf[MAX_TESTED_BITMAP_SIZE];
427   uint i, test_bit;
428   uint no_loops= bitsize > 128 ? 128 : bitsize;
429   bitmap_init(&map2, map2buf, bitsize, false);
430 
431   /* Test all 4 possible combinations of set/unset bits. */
432   for (i=0; i < no_loops; i++)
433   {
434     test_bit=get_rand_bit(bitsize);
435     bitmap_clear_bit(map, test_bit);
436     bitmap_clear_bit(&map2, test_bit);
437     if (!bitmap_is_subset(map, &map2))
438       goto error_is_subset;
439     bitmap_set_bit(map, test_bit);
440     if (bitmap_is_subset(map, &map2))
441       goto error_is_subset;
442     bitmap_set_bit(&map2, test_bit);
443     if (!bitmap_is_subset(map, &map2))
444       goto error_is_subset;
445     bitmap_clear_bit(map, test_bit);
446     if (!bitmap_is_subset(map, &map2))
447       goto error_is_subset;
448     /* Note that test_bit is not cleared i map2. */
449   }
450   bitmap_clear_all(map);
451   bitmap_clear_all(&map2);
452   /* Test all 4 possible combinations of set/unset bits. */
453   for (i=0; i < no_loops; i++)
454   {
455     test_bit=get_rand_bit(bitsize);
456     if (bitmap_is_overlapping(map, &map2))
457       goto error_is_overlapping;
458     bitmap_set_bit(map, test_bit);
459     if (bitmap_is_overlapping(map, &map2))
460       goto error_is_overlapping;
461     bitmap_set_bit(&map2, test_bit);
462     if (!bitmap_is_overlapping(map, &map2))
463       goto error_is_overlapping;
464     bitmap_clear_bit(map, test_bit);
465     if (bitmap_is_overlapping(map, &map2))
466       goto error_is_overlapping;
467     bitmap_clear_bit(&map2, test_bit);
468     /* Note that test_bit is not cleared i map2. */
469   }
470   return false;
471 error_is_subset:
472   ADD_FAILURE() << "is_subset error";
473   return true;
474 error_is_overlapping:
475   ADD_FAILURE() << "is_overlapping error";
476   return true;
477 }
478 
test_intersect(MY_BITMAP * map,uint bitsize)479 bool test_intersect(MY_BITMAP *map, uint bitsize)
480 {
481   uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1);
482   MY_BITMAP map2;
483   my_bitmap_map *map2buf= new my_bitmap_map[bitsize2];
484   uint i, test_bit1, test_bit2, test_bit3;
485   bitmap_init(&map2, map2buf, bitsize2, false);
486 
487   test_bit1= get_rand_bit(bitsize);
488   test_bit2= get_rand_bit(bitsize);
489   bitmap_set_bit(map, test_bit1);
490   bitmap_set_bit(map, test_bit2);
491   test_bit3= get_rand_bit(bitsize2);
492   bitmap_set_bit(&map2, test_bit3);
493   if (test_bit2 < bitsize2)
494     bitmap_set_bit(&map2, test_bit2);
495 
496   bitmap_intersect(map, &map2);
497   if (test_bit2 < bitsize2)
498   {
499     if (!bitmap_is_set(map, test_bit2))
500       goto error;
501     bitmap_clear_bit(map, test_bit2);
502   }
503   if (test_bit1 == test_bit3)
504   {
505     if (!bitmap_is_set(map, test_bit1))
506       goto error;
507     bitmap_clear_bit(map, test_bit1);
508   }
509   if (!bitmap_is_clear_all(map))
510     goto error;
511 
512   bitmap_set_all(map);
513   bitmap_set_all(&map2);
514   for (i=0; i < bitsize2; i++)
515     bitmap_clear_bit(&map2, i);
516   bitmap_intersect(map, &map2);
517   if (!bitmap_is_clear_all(map))
518     goto error;
519   delete[] map2buf;
520   return false;
521 error:
522   ADD_FAILURE() << "intersect error  bit1=" << test_bit1
523                 << ",bit2=" << test_bit2 << ",bit3=" << test_bit3;
524   return true;
525 }
526 
527 #if defined(GTEST_HAS_PARAM_TEST)
528 
529 class BitMapTest : public ::testing::TestWithParam<uint>
530 {
531 protected:
SetUp()532   virtual void SetUp()
533   {
534     bitsize= GetParam();
535     ASSERT_FALSE(bitmap_init(&map, buf, bitsize, false));
536     bitmap_clear_all(&map);
537   }
538 
539   MY_BITMAP map;
540   my_bitmap_map buf[MAX_TESTED_BITMAP_SIZE];
541   uint bitsize;
542 };
543 
544 const uint test_values[]=
545 {
546    1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
547   11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
548   21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
549   31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
550   2*32U - 1, 2*32U, 2*32U + 1,
551   3*32U - 1, 3*32U, 3*32U + 1,
552   4*32U - 1, 4*32U, 4*32U + 1,
553   MAX_TESTED_BITMAP_SIZE
554 };
555 
556 INSTANTIATE_TEST_CASE_P(Foo, BitMapTest,
557                         ::testing::ValuesIn(test_values));
558 
TEST_P(BitMapTest,TestSetGetClearBit)559 TEST_P(BitMapTest, TestSetGetClearBit)
560 {
561   EXPECT_FALSE(test_set_get_clear_bit(&map, bitsize)) << "bitsize=" << bitsize;
562 }
563 
TEST_P(BitMapTest,TestFlipBit)564 TEST_P(BitMapTest, TestFlipBit)
565 {
566   EXPECT_FALSE(test_flip_bit(&map, bitsize)) << "bitsize=" << bitsize;
567 }
568 
TEST_P(BitMapTest,TestGetAllBits)569 TEST_P(BitMapTest, TestGetAllBits)
570 {
571   EXPECT_FALSE(test_get_all_bits(&map, bitsize)) << "bitsize=" << bitsize;
572 }
573 
TEST_P(BitMapTest,TestCompareOperators)574 TEST_P(BitMapTest, TestCompareOperators)
575 {
576   EXPECT_FALSE(test_compare_operators(&map, bitsize)) << "bitsize=" << bitsize;
577 }
578 
TEST_P(BitMapTest,TestCountBitsSet)579 TEST_P(BitMapTest, TestCountBitsSet)
580 {
581   EXPECT_FALSE(test_count_bits_set(&map, bitsize)) << "bitsize=" << bitsize;
582 }
583 
TEST_P(BitMapTest,TestGetFirstBit)584 TEST_P(BitMapTest, TestGetFirstBit)
585 {
586   EXPECT_FALSE(test_get_first_bit(&map, bitsize)) << "bitsize=" << bitsize;
587 }
588 
TEST_P(BitMapTest,TestSetNextBit)589 TEST_P(BitMapTest, TestSetNextBit)
590 {
591   EXPECT_FALSE(test_set_next_bit(&map, bitsize)) << "bitsize=" << bitsize;
592 }
593 
TEST_P(BitMapTest,TestGetNextBit)594 TEST_P(BitMapTest, TestGetNextBit)
595 {
596   EXPECT_FALSE(test_get_next_bit(&map, bitsize)) << "bitsize=" << bitsize;
597 }
598 
TEST_P(BitMapTest,TestPrefix)599 TEST_P(BitMapTest, TestPrefix)
600 {
601   EXPECT_FALSE(test_prefix(&map, bitsize)) << "bitsize=" << bitsize;
602 }
603 
TEST_P(BitMapTest,TestCompare)604 TEST_P(BitMapTest, TestCompare)
605 {
606   EXPECT_FALSE(test_compare(&map, bitsize)) << "bitsize=" << bitsize;
607 }
608 
TEST_P(BitMapTest,TestIntersect)609 TEST_P(BitMapTest, TestIntersect)
610 {
611   EXPECT_FALSE(test_intersect(&map, bitsize)) << "bitsize=" << bitsize;
612 }
613 
614 #endif
615 
616 // Bug#11761614
617 
bitmap_set_prefix_t()618 bool bitmap_set_prefix_t() {
619   MY_BITMAP map;
620   my_bitmap_map buf[2];                         /* 64-bit buffer */
621   uint32 _max= ~((uint32)0);
622   bitmap_init(&map, buf, 32, false);
623 
624   // set all bits in the 2nd half of the buf
625   buf[1]= _max;
626   bitmap_clear_all(&map);
627 
628   /*
629     Choose prefix_size as number that is not a multiple
630     of 8, so that leftover bits in the last prefix byte
631     will be set separately.
632   */
633   bitmap_set_prefix(&map, 31);
634   // 2nd half should remain unaltered
635   return (buf[1] == _max);
636 }
637 
TEST(BitMapTestEx,TestSetPrefixEx)638 TEST(BitMapTestEx, TestSetPrefixEx)
639 {
640   EXPECT_TRUE(bitmap_set_prefix_t());
641 }
642 
643 }
644