File: test_getpwuid_module.c

package info (click to toggle)
nss-wrapper 1.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 888 kB
  • sloc: ansic: 7,947; perl: 372; sh: 26; makefile: 12
file content (61 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "config.h"

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <unistd.h>

#include <pwd.h>

static void test_nwrap_passwd(void **state)
{
	struct passwd *pwd;
	uid_t id = 424242;

	(void) state; /* unused */

	pwd = getpwuid(id);
	assert_non_null(pwd);

	assert_string_equal(pwd->pw_name, "hanswurst");
	assert_int_equal(pwd->pw_uid, id);
	assert_int_equal(pwd->pw_gid, id);
}

static void test_nwrap_passwd_closed_handles(void **state)
{
	struct passwd *pwd;
	uid_t id = 424242;
	long maxfd;

	(void) state; /* unused */

	pwd = getpwuid(id);
	assert_non_null(pwd);

	maxfd = sysconf(_SC_OPEN_MAX);
	if (maxfd < 0) {
		maxfd = 1024;
	}
	for (long fd = 3; fd < maxfd; fd++) {
		close(fd);
	}

	pwd = getpwuid(id);
	assert_non_null(pwd);
}

int main(void)
{
	int rc;

	const struct CMUnitTest tests[] = {
		cmocka_unit_test(test_nwrap_passwd),
		cmocka_unit_test(test_nwrap_passwd_closed_handles),
	};

	rc = cmocka_run_group_tests(tests, NULL, NULL);

	return rc;
}