mirror of
https://github.com/systemd/systemd.git
synced 2024-12-12 11:44:13 +08:00
test: Add tests for gid list ops
This commit is contained in:
parent
afb11bf1b8
commit
c6cecb744b
@ -4,6 +4,7 @@
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "memory-util.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "user-util.h"
|
||||
@ -287,12 +288,41 @@ static void test_make_salt(void) {
|
||||
}
|
||||
|
||||
static void test_in_gid(void) {
|
||||
|
||||
assert(in_gid(getgid()) >= 0);
|
||||
assert(in_gid(getegid()) >= 0);
|
||||
assert(in_gid(getegid()) >= 0); assert(in_gid(TTY_GID) == 0); /* The TTY gid is for owning ttys, it would be really really weird if we were in it. */
|
||||
}
|
||||
|
||||
assert(in_gid(GID_INVALID) < 0);
|
||||
assert(in_gid(TTY_GID) == 0); /* The TTY gid is for owning ttys, it would be really really weird if we were in it. */
|
||||
static void test_gid_lists_ops(void) {
|
||||
static const gid_t l1[] = { 5, 10, 15, 20, 25};
|
||||
static const gid_t l2[] = { 1, 2, 3, 15, 20, 25};
|
||||
static const gid_t l3[] = { 5, 10, 15, 20, 25, 26, 27};
|
||||
static const gid_t l4[] = { 25, 26, 20, 15, 5, 27, 10};
|
||||
|
||||
static const gid_t result1[] = {1, 2, 3, 5, 10, 15, 20, 25, 26, 27};
|
||||
static const gid_t result2[] = {5, 10, 15, 20, 25, 26, 27};
|
||||
|
||||
_cleanup_free_ gid_t *gids = NULL;
|
||||
_cleanup_free_ gid_t *res1 = NULL;
|
||||
_cleanup_free_ gid_t *res2 = NULL;
|
||||
_cleanup_free_ gid_t *res3 = NULL;
|
||||
_cleanup_free_ gid_t *res4 = NULL;
|
||||
int nresult;
|
||||
|
||||
nresult = merge_gid_lists(l2, ELEMENTSOF(l2), l3, ELEMENTSOF(l3), &res1);
|
||||
assert_se(memcmp_nn(res1, nresult, result1, ELEMENTSOF(result1)) == 0);
|
||||
|
||||
nresult = merge_gid_lists(NULL, 0, l2, ELEMENTSOF(l2), &res2);
|
||||
assert_se(memcmp_nn(res2, nresult, l2, ELEMENTSOF(l2)) == 0);
|
||||
|
||||
nresult = merge_gid_lists(l1, ELEMENTSOF(l1), l1, ELEMENTSOF(l1), &res3);
|
||||
assert_se(memcmp_nn(l1, ELEMENTSOF(l1), res3, nresult) == 0);
|
||||
|
||||
nresult = merge_gid_lists(l1, ELEMENTSOF(l1), l4, ELEMENTSOF(l4), &res4);
|
||||
assert_se(memcmp_nn(result2, ELEMENTSOF(result2), res4, nresult) == 0);
|
||||
|
||||
nresult = getgroups_alloc(&gids);
|
||||
assert_se(nresult >= 0 || nresult == -EINVAL || nresult == -ENOMEM);
|
||||
assert_se(gids);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@ -330,6 +360,7 @@ int main(int argc, char *argv[]) {
|
||||
test_make_salt();
|
||||
|
||||
test_in_gid();
|
||||
test_gid_lists_ops();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user