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 <dirent.h>
17 #include <fcntl.h>
18 #include <limits.h>
19 #include <unistd.h>
20 #include "functionalext.h"
21
22 const int FAILED = -1;
23
24 /**
25 * @tc.name : getdents_0100
26 * @tc.desc : Each parameter is valid, the len parameter is less than or equal to INT_MAX, and the directory
27 * information can be read into the specified buffer.
28 * @tc.level : Level 0
29 */
getdents_0100(void)30 void getdents_0100(void)
31 {
32 struct dirent buf;
33 int fd = open("/data/data", O_RDONLY);
34 EXPECT_NE("getdents_0100", fd, -1);
35 int result = getdents(fd, &buf, INT_MAX);
36 EXPECT_TRUE("getdents_0100", result > 0);
37 }
38
39 /**
40 * @tc.name : getdents_0200
41 * @tc.desc : The fd parameter is invalid, the directory information cannot be read into the specified buffer.
42 * @tc.level : Level 2
43 */
getdents_0200(void)44 void getdents_0200(void)
45 {
46 struct dirent buf;
47 int fd = open("/getdents", O_RDONLY);
48 int result = getdents(fd, &buf, INT_MAX);
49 EXPECT_EQ("getdents_0200", result, FAILED);
50 }
51
52 /**
53 * @tc.name : getdents_0300
54 * @tc.desc : The buf parameter is invalid, the directory information cannot be read into the specified buffer.
55 * @tc.level : Level 2
56 */
getdents_0300(void)57 void getdents_0300(void)
58 {
59 struct dirent buf;
60 int fd = open("/data/data", O_RDONLY);
61 EXPECT_NE("getdents_0300", fd, -1);
62 int result = getdents(fd, NULL, INT_MAX);
63 EXPECT_EQ("getdents_0300", result, FAILED);
64 }
65
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68 getdents_0100();
69 getdents_0200();
70 getdents_0300();
71 return t_status;
72 }