• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdbool.h>
17 #include <dirent.h>
18 #include <dlfcn.h>
19 #include <fcntl.h>
20 #include <stdlib.h>
21 #include <stdbool.h>
22 #include <unistd.h>
23 #include "functionalext.h"
24 
25 /**
26  * @tc.name      : fdopendir_0100
27  * @tc.desc      : Each parameter is valid, and the directory information can be obtained.
28  * @tc.level     : Level 0
29  */
fdopendir_0100(void)30 void fdopendir_0100(void)
31 {
32     bool flag = false;
33     DIR *dir = NULL;
34     int fd = open("/data/data", O_RDONLY);
35     EXPECT_NE("fdopendir_0100", fd, -1);
36 
37     dir = fdopendir(fd);
38     EXPECT_TRUE("fdopendir_0100", dir != 0);
39 }
40 
41 /**
42  * @tc.name      : fdopendir_0200
43  * @tc.desc      : The fd parameter is invalid (0), the directory information of the file cannot be obtained.
44  * @tc.level     : Level 2
45  */
fdopendir_0200(void)46 void fdopendir_0200(void)
47 {
48     DIR *dir = fdopendir(0);
49     EXPECT_EQ("fdopendir_0200", dir, NULL);
50 }
51 
52 /**
53  * @tc.name      : fdopendir_0300
54  * @tc.desc      : The fd parameter is invalid (a non-existing directory), and the directory information.
55  *                 of the file cannot be obtained.
56  * @tc.level     : Level 2
57  */
fdopendir_0300(void)58 void fdopendir_0300(void)
59 {
60     DIR *dir = NULL;
61     int fd = open("/data/data/test.txt", O_RDONLY);
62     dir = fdopendir(fd);
63     EXPECT_EQ("fdopendir_0300", dir, NULL);
64 }
65 
66 /**
67  * @tc.name      : fdopendir_0400
68  * @tc.desc      : Each parameter is valid, and the directory information of the file can be obtained.
69  * @tc.level     : Level 2
70  */
fdopendir_0400(void)71 void fdopendir_0400(void)
72 {
73     DIR *dir = NULL;
74     int fd = open("/data/data/test.txt", O_RDONLY);
75     dir = fdopendir(fd);
76     EXPECT_EQ("fdopendir_0400", dir, NULL);
77     remove("/data/data/test.txt");
78 }
79 
main(int argc,char * argv[])80 int main(int argc, char *argv[])
81 {
82     fdopendir_0100();
83     fdopendir_0200();
84     fdopendir_0300();
85     fdopendir_0400();
86     return t_status;
87 }