1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd
5 Copyright 2015 Tom Gundersen
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 int main(int argc
, const char *argv
[]) {
24 _cleanup_bitmap_free_ Bitmap
*b
= NULL
, *b2
= NULL
;
26 unsigned n
= (unsigned) -1, i
= 0;
31 assert_se(bitmap_ensure_allocated(&b
) == 0);
34 assert_se(bitmap_ensure_allocated(&b
) == 0);
36 assert_se(bitmap_isset(b
, 0) == false);
37 assert_se(bitmap_isset(b
, 1) == false);
38 assert_se(bitmap_isset(b
, 256) == false);
39 assert_se(bitmap_isclear(b
) == true);
41 assert_se(bitmap_set(b
, 0) == 0);
42 assert_se(bitmap_isset(b
, 0) == true);
43 assert_se(bitmap_isclear(b
) == false);
45 assert_se(bitmap_isset(b
, 0) == false);
46 assert_se(bitmap_isclear(b
) == true);
48 assert_se(bitmap_set(b
, 1) == 0);
49 assert_se(bitmap_isset(b
, 1) == true);
50 assert_se(bitmap_isclear(b
) == false);
52 assert_se(bitmap_isset(b
, 1) == false);
53 assert_se(bitmap_isclear(b
) == true);
55 assert_se(bitmap_set(b
, 256) == 0);
56 assert_se(bitmap_isset(b
, 256) == true);
57 assert_se(bitmap_isclear(b
) == false);
59 assert_se(bitmap_isset(b
, 256) == false);
60 assert_se(bitmap_isclear(b
) == true);
62 assert_se(bitmap_set(b
, 32) == 0);
64 assert_se(bitmap_isset(b
, 32) == true);
67 BITMAP_FOREACH(n
, NULL
, it
)
68 assert_not_reached("NULL bitmap");
70 assert_se(bitmap_set(b
, 0) == 0);
71 assert_se(bitmap_set(b
, 1) == 0);
72 assert_se(bitmap_set(b
, 256) == 0);
74 BITMAP_FOREACH(n
, b
, it
) {
84 assert_se(i
== (unsigned) -1);
88 BITMAP_FOREACH(n
, b
, it
) {
98 assert_se(i
== (unsigned) -1);
101 assert_se(bitmap_isclear(b
) == true);
103 assert_se(bitmap_set(b
, (unsigned) -1) == -ERANGE
);
107 assert_se(bitmap_ensure_allocated(&b
) == 0);
108 assert_se(bitmap_ensure_allocated(&b2
) == 0);
110 assert_se(bitmap_equal(b
, b2
));
111 assert_se(bitmap_set(b
, 0) == 0);
113 assert_se(bitmap_equal(b
, b2
));
115 assert_se(bitmap_set(b
, 1) == 0);
117 assert_se(bitmap_equal(b
, b2
));
119 assert_se(bitmap_set(b
, 0) == 0);
120 assert_se(bitmap_set(b2
, 0) == 0);
121 assert_se(bitmap_equal(b
, b2
));