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 "functionalext.h"
18
19 #define MAXPATH 1000
20
21 /**
22 * @tc.name : closedir_0100
23 * @tc.desc : The parameter is valid and can close the specified directory.
24 * @tc.level : Level 0
25 */
closedir_0100(void)26 void closedir_0100(void)
27 {
28 char path[MAXPATH];
29 DIR *dir_ptr;
30 char *data = NULL;
31 data = getcwd(path, MAXPATH);
32 dir_ptr = opendir(path);
33 int ret = -1;
34 ret = closedir(dir_ptr);
35 EXPECT_EQ("closedir_0100", ret, 0);
36 }
37
38 /**
39 * @tc.name : closedir_0200
40 * @tc.desc : The dir parameter is invalid, the specified directory cannot be closed.
41 * @tc.level : Level 2
42 */
closedir_0200(void)43 void closedir_0200(void)
44 {
45 DIR *dir = (DIR *)"/notexist";
46 int ret = 0;
47 ret = closedir(dir);
48 EXPECT_EQ("closedir_0200", ret, -1);
49 }
50
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53 closedir_0100();
54 closedir_0200();
55 return t_status;
56 }