2 This file is part of systemd
4 Copyright 2015 Tom Gundersen
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 int main(int argc
, const char *argv
[]) {
23 _cleanup_bitmap_free_ Bitmap
*b
= NULL
;
25 unsigned n
= (unsigned) -1, i
= 0;
30 assert_se(bitmap_ensure_allocated(&b
) == 0);
33 assert_se(bitmap_ensure_allocated(&b
) == 0);
35 assert_se(bitmap_isset(b
, 0) == false);
36 assert_se(bitmap_isset(b
, 1) == false);
37 assert_se(bitmap_isset(b
, 256) == false);
38 assert_se(bitmap_isclear(b
) == true);
40 assert_se(bitmap_set(b
, 0) == 0);
41 assert_se(bitmap_isset(b
, 0) == true);
42 assert_se(bitmap_isclear(b
) == false);
44 assert_se(bitmap_isset(b
, 0) == false);
45 assert_se(bitmap_isclear(b
) == true);
47 assert_se(bitmap_set(b
, 1) == 0);
48 assert_se(bitmap_isset(b
, 1) == true);
49 assert_se(bitmap_isclear(b
) == false);
51 assert_se(bitmap_isset(b
, 1) == false);
52 assert_se(bitmap_isclear(b
) == true);
54 assert_se(bitmap_set(b
, 256) == 0);
55 assert_se(bitmap_isset(b
, 256) == true);
56 assert_se(bitmap_isclear(b
) == false);
58 assert_se(bitmap_isset(b
, 256) == false);
59 assert_se(bitmap_isclear(b
) == true);
61 assert_se(bitmap_set(b
, 0) == 0);
62 assert_se(bitmap_set(b
, 1) == 0);
63 assert_se(bitmap_set(b
, 256) == 0);
65 BITMAP_FOREACH(n
, b
, it
) {
75 assert_se(i
== (unsigned) -1);
79 BITMAP_FOREACH(n
, b
, it
) {
89 assert_se(i
== (unsigned) -1);
92 assert_se(bitmap_isclear(b
) == true);
94 assert_se(bitmap_set(b
, (unsigned) -1) == -ERANGE
);