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 <pwd.h>
17 #include "functionalext.h"
18
19 #define TEST_BUFFER_SIZE 128
20
21 /**
22 * @tc.name : getpwuid_r_0100
23 * @tc.desc : Get account information based on the current uid
24 * @tc.level : Level 0
25 */
getpwuid_r_0100(void)26 void getpwuid_r_0100(void)
27 {
28 struct passwd pw;
29 struct passwd *res = NULL;
30 char buf[TEST_BUFFER_SIZE];
31
32 int ret = getpwuid_r(getuid(), &pw, buf, sizeof(buf), &res);
33 EXPECT_EQ("getpwuid_r_0100", ret, CMPFLAG);
34 if (!ret) {
35 EXPECT_EQ("getpwuid_r_0100", pw.pw_uid, getuid());
36 }
37 }
38
39 /**
40 * @tc.name : getpwuid_r_0200
41 * @tc.desc : Incorrect cache size, get account information based on current uid
42 * @tc.level : Level 2
43 */
getpwuid_r_0200(void)44 void getpwuid_r_0200(void)
45 {
46 struct passwd pw;
47 struct passwd *res = NULL;
48 char buf[TEST_BUFFER_SIZE];
49
50 int ret = getpwuid_r(getuid(), &pw, buf, 1, &res);
51 EXPECT_EQ("getpwuid_r_0200", ret, ERANGE);
52 }
53
main(void)54 int main(void)
55 {
56 getpwuid_r_0100();
57 getpwuid_r_0200();
58 return t_status;
59 }