1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <errno.h>
17 #include <stdlib.h>
18 #include <sys/wait.h>
19 #include "functionalext.h"
20
21 /**
22 * @tc.name : getresuid_0100
23 * @tc.desc : Get the real UID, the effective UID, and the saved set-user-ID of the calling process
24 * @tc.level : Level 0
25 */
getresuid_0100(void)26 void getresuid_0100(void)
27 {
28 uid_t ruid = -1;
29 uid_t euid = -1;
30 uid_t suid = -1;
31 int rev = getresuid(&ruid, &euid, &suid);
32 EXPECT_EQ("getresuid_0100", rev, 0);
33 }
34
35 /**
36 * @tc.name : getresuid_0200
37 * @tc.desc : Get the real UID, the effective UID, and the saved set-user-ID of the child process
38 * @tc.level : Level 0
39 */
getresuid_0200(void)40 void getresuid_0200(void)
41 {
42 pid_t pid = fork();
43 if (pid == 0) {
44 uid_t ruid = -1;
45 uid_t euid = -1;
46 uid_t suid = -1;
47 int rev = getresuid(&ruid, &euid, &suid);
48 EXPECT_EQ("getresuid_0200", rev, 0);
49 } else if (pid > 0) {
50 wait(NULL);
51 }
52 }
53
54 /**
55 * @tc.name : getresuid_0300
56 * @tc.desc : Provide wrong arguments, call getresuid
57 * @tc.level : Level 2
58 */
getresuid_0300(void)59 void getresuid_0300(void)
60 {
61 int rev = getresuid(NULL, NULL, NULL);
62 EXPECT_EQ("getresuid_0300", rev, -1);
63 }
64
main(void)65 int main(void)
66 {
67 getresuid_0100();
68 getresuid_0200();
69 getresuid_0300();
70 return t_status;
71 }