]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-uid-range.c
resolved: don't check conflicts for DNS-SD enumeration RRs
[thirdparty/systemd.git] / src / test / test-uid-range.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8530dc44
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2014 Lennart Poettering
6
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.
11
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.
16
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/>.
19***/
20
21#include <stddef.h>
22
b5efdb8a 23#include "alloc-util.h"
8530dc44 24#include "uid-range.h"
ee104e11
LP
25#include "user-util.h"
26#include "util.h"
8530dc44
LP
27
28int main(int argc, char *argv[]) {
29 _cleanup_free_ UidRange *p = NULL;
30 unsigned n = 0;
31 uid_t search;
32
33 assert_se(uid_range_add_str(&p, &n, "500-999") >= 0);
34 assert_se(n == 1);
35 assert_se(p[0].start == 500);
20755373 36 assert_se(p[0].nr == 500);
8530dc44
LP
37
38 assert_se(!uid_range_contains(p, n, 499));
39 assert_se(uid_range_contains(p, n, 500));
40 assert_se(uid_range_contains(p, n, 999));
41 assert_se(!uid_range_contains(p, n, 1000));
42
fed1e721 43 search = UID_INVALID;
8530dc44
LP
44 assert_se(uid_range_next_lower(p, n, &search));
45 assert_se(search == 999);
46 assert_se(uid_range_next_lower(p, n, &search));
47 assert_se(search == 998);
48 search = 501;
49 assert_se(uid_range_next_lower(p, n, &search));
50 assert_se(search == 500);
51 assert_se(uid_range_next_lower(p, n, &search) == -EBUSY);
52
53 assert_se(uid_range_add_str(&p, &n, "1000") >= 0);
54 assert_se(n == 1);
55 assert_se(p[0].start == 500);
20755373 56 assert_se(p[0].nr == 501);
8530dc44
LP
57
58 assert_se(uid_range_add_str(&p, &n, "30-40") >= 0);
59 assert_se(n == 2);
60 assert_se(p[0].start == 30);
20755373 61 assert_se(p[0].nr == 11);
8530dc44 62 assert_se(p[1].start == 500);
20755373 63 assert_se(p[1].nr == 501);
8530dc44
LP
64
65 assert_se(uid_range_add_str(&p, &n, "60-70") >= 0);
66 assert_se(n == 3);
67 assert_se(p[0].start == 30);
20755373 68 assert_se(p[0].nr == 11);
8530dc44 69 assert_se(p[1].start == 60);
20755373 70 assert_se(p[1].nr == 11);
8530dc44 71 assert_se(p[2].start == 500);
20755373 72 assert_se(p[2].nr == 501);
8530dc44
LP
73
74 assert_se(uid_range_add_str(&p, &n, "20-2000") >= 0);
75 assert_se(n == 1);
76 assert_se(p[0].start == 20);
20755373 77 assert_se(p[0].nr == 1981);
8530dc44
LP
78
79 assert_se(uid_range_add_str(&p, &n, "2002") >= 0);
80 assert_se(n == 2);
81 assert_se(p[0].start == 20);
20755373 82 assert_se(p[0].nr == 1981);
8530dc44 83 assert_se(p[1].start == 2002);
20755373 84 assert_se(p[1].nr == 1);
8530dc44
LP
85
86 assert_se(uid_range_add_str(&p, &n, "2001") >= 0);
87 assert_se(n == 1);
88 assert_se(p[0].start == 20);
20755373 89 assert_se(p[0].nr == 1983);
8530dc44
LP
90
91 return 0;
92}