Mercurial > gnulib
annotate tests/test-priv-set.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
1 /* Test the priv-set module. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
3 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
7 (at your option) any later version. |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
8 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
13 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
16 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
17 /* Written by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2007. */ |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
18 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
19 #include <config.h> |
12487
8ba9831d54bf
Include header file being tested immediately after config.h.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
20 |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
21 #include "priv-set.h" |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
22 |
13422
e81addc3d284
priv-set: Don't assume that priv.h exists merely because getppriv does.
Paul Eggert <eggert@cs.ucla.edu>
parents:
12559
diff
changeset
|
23 #if HAVE_GETPPRIV && HAVE_PRIV_H |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
24 # include <priv.h> |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
25 #endif |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
26 #include <unistd.h> |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
27 #include <errno.h> |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
28 #include <sys/types.h> |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
29 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12487
diff
changeset
|
30 #include "macros.h" |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
31 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
32 int |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
33 main (void) |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
34 { |
13422
e81addc3d284
priv-set: Don't assume that priv.h exists merely because getppriv does.
Paul Eggert <eggert@cs.ucla.edu>
parents:
12559
diff
changeset
|
35 #if HAVE_GETPPRIV && HAVE_PRIV_H |
11538
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
36 priv_set_t *set; |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
37 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
38 ASSERT (set = priv_allocset ()); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
39 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
40 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
41 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
42 /* Do a series of removes and restores making sure that the results are |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
43 consistent with our ismember function and solaris' priv_ismember. */ |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
44 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
45 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
46 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
47 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
48 ASSERT (errno == EINVAL); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
49 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
50 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
51 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
52 ASSERT (priv_set_remove (PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
53 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
54 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
55 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
56 ASSERT (priv_set_remove (PRIV_PROC_EXEC) == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
57 ASSERT (errno == EINVAL); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
58 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
59 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
60 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
61 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
62 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
63 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
64 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
65 ASSERT (priv_set_restore (PRIV_PROC_EXEC) == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
66 ASSERT (errno == EINVAL); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
67 ASSERT (priv_set_ismember (PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
68 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
69 ASSERT (priv_ismember (set, PRIV_PROC_EXEC) == 1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
70 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
71 /* Test the priv_set_linkdir wrappers. */ |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
72 ASSERT (getppriv (PRIV_EFFECTIVE, set) == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
73 if (priv_ismember (set, PRIV_SYS_LINKDIR)) |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
74 { |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
75 ASSERT (priv_set_restore_linkdir () == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
76 ASSERT (errno == EINVAL); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
77 ASSERT (priv_set_remove_linkdir () == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
78 ASSERT (priv_set_remove_linkdir () == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
79 ASSERT (errno == EINVAL); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
80 ASSERT (priv_set_restore_linkdir () == 0); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
81 } |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
82 #else |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
83 ASSERT (priv_set_restore_linkdir () == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
84 ASSERT (priv_set_remove_linkdir () == -1); |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
85 #endif |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
86 |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
87 return 0; |
af683213eeb0
priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
diff
changeset
|
88 } |