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 <limits.h>
17 #include <unistd.h>
18 #include "functionalext.h"
19
20 #define TEST_LIMIT_ERROR 1000
21 #define TEST_LIMIT_SIZE 3
22 struct limit_data {
23 int name;
24 long limit;
25 };
26
27 /**
28 * @tc.name : pathconf_0100
29 * @tc.desc : Get file-related configuration values
30 * @tc.level : Level 0
31 */
pathconf_0100(void)32 void pathconf_0100(void)
33 {
34 struct limit_data data[TEST_LIMIT_SIZE] = {
35 {.name = _PC_PATH_MAX, .limit = PATH_MAX},
36 {.name = _PC_PIPE_BUF, .limit = PIPE_BUF},
37 {.name = _PC_NAME_MAX, .limit = NAME_MAX},
38 };
39
40 int i;
41 long ret;
42 for (i = 0; i < TEST_LIMIT_SIZE; i++) {
43 ret = pathconf(".", data[i].name);
44 EXPECT_EQ("pathconf_0100", ret, data[i].limit);
45 }
46 }
47
48 /**
49 * @tc.name : pathconf_0200
50 * @tc.desc : Provide exception parameters to get configuration values related to files
51 * @tc.level : Level 2
52 */
pathconf_0200(void)53 void pathconf_0200(void)
54 {
55 long ret = pathconf(".", TEST_LIMIT_ERROR);
56 EXPECT_EQ("pathconf_0200", ret, ERREXPECT);
57
58 ret = pathconf(NULL, PATH_MAX);
59 EXPECT_EQ("pathconf_0200", ret, ERREXPECT);
60
61 ret = pathconf("not_exist", PATH_MAX);
62 EXPECT_EQ("pathconf_0200", ret, ERREXPECT);
63 }
64
main(void)65 int main(void)
66 {
67 pathconf_0100();
68 pathconf_0200();
69 return t_status;
70 }