diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 13:00:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 13:00:47 +0000 |
commit | 2cb7e0aaedad73b076ea18c6900b0e86c5760d79 (patch) | |
tree | da68ca54bb79f4080079bf0828acda937593a4e1 /src/test/test-uid-range.c | |
parent | Initial commit. (diff) | |
download | systemd-2cb7e0aaedad73b076ea18c6900b0e86c5760d79.tar.xz systemd-2cb7e0aaedad73b076ea18c6900b0e86c5760d79.zip |
Adding upstream version 247.3.upstream/247.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-uid-range.c')
-rw-r--r-- | src/test/test-uid-range.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/test-uid-range.c b/src/test/test-uid-range.c new file mode 100644 index 0000000..16cbab0 --- /dev/null +++ b/src/test/test-uid-range.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <stddef.h> + +#include "alloc-util.h" +#include "uid-range.h" +#include "user-util.h" +#include "util.h" + +int main(int argc, char *argv[]) { + _cleanup_free_ UidRange *p = NULL; + unsigned n = 0; + uid_t search; + + assert_se(uid_range_add_str(&p, &n, "500-999") >= 0); + assert_se(n == 1); + assert_se(p[0].start == 500); + assert_se(p[0].nr == 500); + + assert_se(!uid_range_contains(p, n, 499)); + assert_se(uid_range_contains(p, n, 500)); + assert_se(uid_range_contains(p, n, 999)); + assert_se(!uid_range_contains(p, n, 1000)); + + search = UID_INVALID; + assert_se(uid_range_next_lower(p, n, &search)); + assert_se(search == 999); + assert_se(uid_range_next_lower(p, n, &search)); + assert_se(search == 998); + search = 501; + assert_se(uid_range_next_lower(p, n, &search)); + assert_se(search == 500); + assert_se(uid_range_next_lower(p, n, &search) == -EBUSY); + + assert_se(uid_range_add_str(&p, &n, "1000") >= 0); + assert_se(n == 1); + assert_se(p[0].start == 500); + assert_se(p[0].nr == 501); + + assert_se(uid_range_add_str(&p, &n, "30-40") >= 0); + assert_se(n == 2); + assert_se(p[0].start == 30); + assert_se(p[0].nr == 11); + assert_se(p[1].start == 500); + assert_se(p[1].nr == 501); + + assert_se(uid_range_add_str(&p, &n, "60-70") >= 0); + assert_se(n == 3); + assert_se(p[0].start == 30); + assert_se(p[0].nr == 11); + assert_se(p[1].start == 60); + assert_se(p[1].nr == 11); + assert_se(p[2].start == 500); + assert_se(p[2].nr == 501); + + assert_se(uid_range_add_str(&p, &n, "20-2000") >= 0); + assert_se(n == 1); + assert_se(p[0].start == 20); + assert_se(p[0].nr == 1981); + + assert_se(uid_range_add_str(&p, &n, "2002") >= 0); + assert_se(n == 2); + assert_se(p[0].start == 20); + assert_se(p[0].nr == 1981); + assert_se(p[1].start == 2002); + assert_se(p[1].nr == 1); + + assert_se(uid_range_add_str(&p, &n, "2001") >= 0); + assert_se(n == 1); + assert_se(p[0].start == 20); + assert_se(p[0].nr == 1983); + + return 0; +} |