• 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 <errno.h>
17 #include <fcntl.h>
18 #include <stdlib.h>
19 #include <sys/stat.h>
20 #include "functionalext.h"
21 
22 const int32_t CREAT_MODE = 666;
23 
24 /**
25  * @tc.name      : stat_0100
26  * @tc.desc      : Verify stat process success with two params
27  * @tc.level     : Level 0
28  */
stat_0100(void)29 void stat_0100(void)
30 {
31     struct stat buf;
32     int fd = -1;
33     fd = creat("test1.txt", CREAT_MODE);
34     if (fd < 0) {
35         EXPECT_MT("stat_0100", fd, 0);
36         return;
37     } else {
38         close(fd);
39     }
40     int32_t ret = stat("test1.txt", &buf);
41     EXPECT_EQ("stat_0100", ret, 0);
42     EXPECT_EQ("stat_0100", buf.st_size, 0);
43     ret = remove("test1.txt");
44     EXPECT_EQ("stat_0100", ret, 0);
45 }
46 
47 /**
48  * @tc.name      : stat_0200
49  * @tc.desc      : Verify stat process fail because file is not exit
50  * @tc.level     : Level 2
51  */
stat_0200(void)52 void stat_0200(void)
53 {
54     struct stat buf;
55     int32_t ret = stat("test2.txt", &buf);
56     EXPECT_EQ("stat_0200", ret, -1);
57 }
58 
main(void)59 int main(void)
60 {
61     stat_0100();
62     stat_0200();
63     return t_status;
64 }
65