]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-uid-range.c
2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
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 #include "alloc-util.h"
23 #include "uid-range.h"
24 #include "user-util.h"
27 int main(int argc
, char *argv
[]) {
28 _cleanup_free_ UidRange
*p
= NULL
;
32 assert_se(uid_range_add_str(&p
, &n
, "500-999") >= 0);
34 assert_se(p
[0].start
== 500);
35 assert_se(p
[0].nr
== 500);
37 assert_se(!uid_range_contains(p
, n
, 499));
38 assert_se(uid_range_contains(p
, n
, 500));
39 assert_se(uid_range_contains(p
, n
, 999));
40 assert_se(!uid_range_contains(p
, n
, 1000));
43 assert_se(uid_range_next_lower(p
, n
, &search
));
44 assert_se(search
== 999);
45 assert_se(uid_range_next_lower(p
, n
, &search
));
46 assert_se(search
== 998);
48 assert_se(uid_range_next_lower(p
, n
, &search
));
49 assert_se(search
== 500);
50 assert_se(uid_range_next_lower(p
, n
, &search
) == -EBUSY
);
52 assert_se(uid_range_add_str(&p
, &n
, "1000") >= 0);
54 assert_se(p
[0].start
== 500);
55 assert_se(p
[0].nr
== 501);
57 assert_se(uid_range_add_str(&p
, &n
, "30-40") >= 0);
59 assert_se(p
[0].start
== 30);
60 assert_se(p
[0].nr
== 11);
61 assert_se(p
[1].start
== 500);
62 assert_se(p
[1].nr
== 501);
64 assert_se(uid_range_add_str(&p
, &n
, "60-70") >= 0);
66 assert_se(p
[0].start
== 30);
67 assert_se(p
[0].nr
== 11);
68 assert_se(p
[1].start
== 60);
69 assert_se(p
[1].nr
== 11);
70 assert_se(p
[2].start
== 500);
71 assert_se(p
[2].nr
== 501);
73 assert_se(uid_range_add_str(&p
, &n
, "20-2000") >= 0);
75 assert_se(p
[0].start
== 20);
76 assert_se(p
[0].nr
== 1981);
78 assert_se(uid_range_add_str(&p
, &n
, "2002") >= 0);
80 assert_se(p
[0].start
== 20);
81 assert_se(p
[0].nr
== 1981);
82 assert_se(p
[1].start
== 2002);
83 assert_se(p
[1].nr
== 1);
85 assert_se(uid_range_add_str(&p
, &n
, "2001") >= 0);
87 assert_se(p
[0].start
== 20);
88 assert_se(p
[0].nr
== 1983);